/*
* 能发送ajax请求的函数模块
* 函数的返回值是promise对象*/
import axios from 'axios'

/*export default function ajax(url,data={},type='GET') {
    if(type==='GET'){
        //拼请求参数 字符串
        //data:{username:'tom',password:123}
        //paramStr:username=tom&password=123
        let paramStr =''
        Object.keys(data).forEach(key=>{
           paramStr+=key+'='+data[key]+'&'
        })
        if (paramStr){
            paramStr =paramStr.substring(0,paramStr.length-1)
        }
    //测试
        //console.log(url+'?'+paramStr)
        return axios.get(url+'?'+paramStr)
    }else{
        return axios.post(url,data)
    }
}*/
export default function ajax(url,data={},type='GET') {
    if(type==='GET'){

        return axios({
            url,
            params:data
        })
    }else{
        return axios.post(url,data)
    }
}
